#include "SpriteBarrel.h"

SpriteBarrel::SpriteBarrel(CL_GraphicContext gc){
	barrelContext = gc;
	for(int h=0;h<-FRAMES_BARREL;h++){
		barrelResources[h]=NULL;
	}
	barrelResources[0]= new CL_ResourceManager("BarrelRolling.xml");
	barrelResources[1]= new CL_ResourceManager("BarrelFalling.xml");
	for(int i=0;i<FRAMES_BARREL;i++){
		barrelSprites[i]=NULL;
	}
	barrelSprites[0]=new CL_Sprite(gc, "BarrelRolling", barrelResources[0]);
	barrelSprites[1]=new CL_Sprite(gc, "BarrelFalling", barrelResources[1]);
}

void SpriteBarrel::drawrollingbarrel(CL_Vec2<int> position)
{
	barrelSprites[0]->draw(barrelContext, position.x, position.y);
	barrelSprites[0]->update();
}

void SpriteBarrel::drawfallingbarrel(CL_Vec2<int> position)
{
	barrelSprites[1]->draw(barrelContext, position.x, position.y);
}

SpriteBarrel::~SpriteBarrel(){
	for each(CL_Sprite* s in barrelSprites){
		if(s!=NULL){
			delete s;
			s=NULL;
		}
		
	}
	for each(CL_ResourceManager* rs in barrelResources){
		if(rs!=NULL){
			delete rs;
			rs=NULL;
		}
		
	}
}